﻿using com.yoozoo.gta.Gameplay.RTS;
using UnityEngine;
using Yoozoo.Core.Extensions.Engine;

namespace Yoozoo.Gameplay.RTS
{
    public class CargoTruckHud : HudBase
    {
        private CargoTruckHudLod0 cargoTruckHudLod0;
        private GameObject cargoTruckHudLod0Obj;
        private GameObject cargoTruckHudLod1Obj;
        private long bindEntityTid;

        public override void Initialize(int team)
        {
            base.Initialize(team);
            var hudManager = ArmyManager.Instance.HudManager;
            if (cargoTruckHudLod0Obj == null)
            {
                cargoTruckHudLod0Obj = hudManager.GetHud(HudManager.CargoTruckLod0);
            }
            cargoTruckHudLod0 = cargoTruckHudLod0Obj.GetComponent<CargoTruckHudLod0>();
            if (cargoTruckHudLod1Obj == null)
            {
                cargoTruckHudLod1Obj = hudManager.GetHud(HudManager.CargoTruckLod1);
            }
        }

        public override void Dispose()
        {
            base.Dispose();
            var hudManager = ArmyManager.Instance.HudManager;
            hudManager.RecoverHud(HudManager.CargoTruckLod0, cargoTruckHudLod0Obj);
            hudManager.RecoverHud(HudManager.CargoTruckLod1, cargoTruckHudLod1Obj);
        }

        public void SetEntityAndTroopData(MarchEntity marchEntity, RtsServerInfo serverInfo)
        {
            if (bindEntityTid == default(long) || marchEntity.Tid == bindEntityTid)
            {
                MarchEntity = marchEntity;
                bindEntityTid = marchEntity.Tid;
            }
        }
        
        public override void Hide()
        {
            base.Hide();
            if (cargoTruckHudLod0Obj)
            {
                cargoTruckHudLod0Obj.transform.position = invisiblePosition;
            }
            if (cargoTruckHudLod1Obj)
            {
                cargoTruckHudLod1Obj.transform.position = invisiblePosition;
            }
        }

        public override void UpdateFollowPos()
        {
            base.UpdateFollowPos();
            if (MarchEntity.Tid == bindEntityTid)
            {
                if (cargoTruckHudLod0Obj != null)
                {
                    var parentPos = MarchEntity.Transform.position;
                    cargoTruckHudLod0Obj.transform.localPosition = parentPos;
                }
                if (cargoTruckHudLod1Obj != null)
                {
                    var parentPos = MarchEntity.Transform.position;
                    cargoTruckHudLod1Obj.transform.localPosition = parentPos;
                }
            }
        }

        public void UpdateShow()
        {
            cargoTruckHudLod0.RefreshShow(MarchEntity.RtsServerInfo);
        }

        public void SetDescTextInfo(bool bIsActiveDescText, string content)
        {
            cargoTruckHudLod0.RefreshDescText(bIsActiveDescText, content);
        }

        public void SetTroopCount(int troopCount)
        {
            cargoTruckHudLod0.SetTroopCount(troopCount);
        }

        protected override void OnLod0ScaleChanged(MarchContext marchContext)
        {
            base.SetHudLodScale(LodHudType.CargoTruckHud, cargoTruckHudLod0Obj, marchContext);
            cargoTruckHudLod0Obj.SetActive(true);
            cargoTruckHudLod1Obj.SetActive(false);
        }

        protected override void OnLod1ScaleChanged(MarchContext marchContext)
        {
            cargoTruckHudLod0Obj.SetActive(false);
            cargoTruckHudLod1Obj.SetActive(true);
        }

        protected override void SelfInit()
        {
        }

        protected override void InitParentScaleAndPosition()
        {
        }

        public override void SetSelected(bool selected, bool isMultySelect)
        {
        }

        public override void UpdatePlayerName()
        {
        }

        protected override void InitSoldierNumAndRage()
        {
        }

        public override void OnCameraPosUpdated(MarchContext marchContext)
        {
        }
        protected override void InitDefaultTrigger()
        {
        }

        public override void ForceShowSelectedUI(bool isShow, bool isBattleStyle)
        {
        }
    }
}
